/*
 * Copyright 2010 - 2011, The PLDesktop Development Team
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 */

#ifndef TAR_FILE_H
#define TAR_FILE_H

#include <lib/tarheader.h>
#include <lib/tarfile.h>
#include <tools/PLRadixTree.h>
using namespace PLSDK;

/**
 * File information element from a tar file or dir element.
 */
class TarFile {
    friend class Tar;
public:
    /**
     * Constructor.
     *
     * @param newFilename The filename.
     * @param newType The type of the file.
     * @param newLinkedName The name of the file to link to if the file was a link.
     * @param newSize The size of the file.
     * @param newStartPosition The start address of the file data.
     * @param subnodes The subnodes for a directory.
     */
    TarFile(const char *newFilename, TarHeader::FileType newType, const char *newLinkedName, uint32_t newSize, uint32_t newStartPosition = 0, PLRadixTree<TarFile *> *subnodes = 0);
    /**
     * Destructor.
     */
    ~TarFile();
    /**
     * Get the filename.
     *
     * @return The filename.
     */
    inline const char *filename();
    /**
     * Get the type of the file.
     *
     * @return The file.
     */
    inline TarHeader::FileType type();
    /**
     * Get the name of the linked file.
     *
     * @return The filename that was linked to.
     */
    inline const char *linkedName();
    /**
     * Get the size of the file.
     *
     * @return The size.
     */
    inline uint32_t fileSize();
    /**
     * Get the start position of the file or 0 for a directory.
     *
     * @return The start position of the file.
     */
    inline uint32_t startPosition();
    /**
     * Get the subnodes if the file was a directory.
     *
     * @return The directory entries or 0 if the file was not a directory.
     */
    inline PLRadixTree<TarFile *> *subnodes();
private:
    const char *m_filename;
    TarHeader::FileType m_type;
    const char *m_linkedName;
    uint32_t m_fileSize;
    uint32_t m_startPosition;
    PLRadixTree<TarFile *> *m_subnodes;
};

PLRadixTree<TarFile *> *TarFile::subnodes() {
    return m_subnodes;
}

const char *TarFile::filename() {
    return m_filename;
}

TarHeader::FileType TarFile::type() {
    return m_type;
}

const char *TarFile::linkedName() {
    return m_linkedName;
}

uint32_t TarFile::fileSize() {
    return m_fileSize;
}

uint32_t TarFile::startPosition() {
    return m_startPosition;
}

#endif
